package com.fa7.android.example.listafacil;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;

public class AddActivity extends Activity {
	CategoriaDB catDB;
	
	private TextView mTotalValueTextView;
	private Button mAddImageButton;
	private Button mAddCompraButton;
	private EditText mValueEdit;
	private EditText mNameEdit;
	private EditText mQtdEdit;
	private ImageView mImage;
	
	Spinner spinner;
//	Cursor c;
//	String[] from = new String[]{"name"};
//	int[] to = new int[]{android.R.id.text1};
//	SimpleCursorAdapter cAdapter = null;
	ArrayAdapter<String> dataAdapter;
	List<Categoria> categorias;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		catDB = new CategoriaDB(this);
		categorias = catDB.queryAll();
		setContentView(R.layout.add_layout);
		spinner = (Spinner) findViewById(R.id.combobox_categoria);
//		c = catDB.queryAllCursor();
		/*cAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, c, from, to,0);
		cAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);*/
		List<String> labels = new ArrayList<String>();
		for(Categoria cat : categorias){
			labels.add(cat.getId()+"-"+cat.getName());
		}
		dataAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, labels);
	    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
	    spinner.setAdapter(dataAdapter);
		
		mTotalValueTextView = (TextView)findViewById(R.id.add_total_value);
		mAddImageButton = (Button)findViewById(R.id.add_image_button);
		mImage = (ImageView)findViewById(R.id.add_image);
		mAddCompraButton = (Button)findViewById(R.id.add_button);
		mValueEdit = (EditText)findViewById(R.id.add_preco);
		mNameEdit = (EditText)findViewById(R.id.add_name);
		mQtdEdit = (EditText)findViewById(R.id.add_qtd);
	}
	
}
